package com.weiadmin.interceptor;

import com.weiadmin.exception.GlobalException;
import com.weiadmin.response.RestResponse;
import io.micrometer.common.util.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 功能描述
 *
 * @author: shizhongyu
 * @date: 2023年03月18日 16:42
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //通过query的方式获取token
//        String token = request.getParameter("token");
        //通过header的方式获取token
        String token = request.getHeader("token");
        if(StringUtils.isEmpty(token)){
            RestResponse<Object> httpresponse = new RestResponse<>();
            throw new GlobalException("请先登录");
        }
        return true;
    }
}
